package com.bw.purchase.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bw.po.TbHouseGroupBuying;
import com.bw.po.TbHouseOrder;
import com.bw.purchase.mapper.TbHouseGroupBuyingMapper;
import com.bw.purchase.service.TbHouseGroupBuyingService;
import com.bw.result.ResponseState;
import com.bw.result.ResultVo;
import com.bw.vo.IdVo;
import com.bw.vo.TbHouseGroupBuyingSearchVo;
import com.bw.vo.TbHouseGroupBuyingVo;
import nonapi.io.github.classgraph.json.Id;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author lenovo
* @description 针对表【tb_house_group_buying(团购表)】的数据库操作Service实现
* @createDate 2023-11-11 10:08:34
*/
@Service
public class TbHouseGroupBuyingServiceImpl extends ServiceImpl<TbHouseGroupBuyingMapper, TbHouseGroupBuying>
    implements TbHouseGroupBuyingService {

    @Autowired
    private TbHouseGroupBuyingMapper tbHouseGroupBuyingMapper;

    @Override
    public ResultVo add(TbHouseGroupBuyingVo tbHouseGroupBuyingVo) {
        TbHouseGroupBuying tbHouseGroupBuying = new TbHouseGroupBuying();
        BeanUtils.copyProperties(tbHouseGroupBuyingVo,tbHouseGroupBuying);
        int flag = tbHouseGroupBuyingMapper.insert(tbHouseGroupBuying);
        return flag>0?ResultVo.SUCCESS():ResultVo.FAILED(ResponseState.INSERT_ERROR);
    }

    @Override
    public ResultVo del(IdVo idVo) {
        int flag = tbHouseGroupBuyingMapper.deleteById(idVo.getId());
        return flag>0?ResultVo.SUCCESS():ResultVo.FAILED(ResponseState.DELETE_ERROR);
    }

    @Override
    public ResultVo updateByVo(TbHouseGroupBuyingVo tbHouseGroupBuyingVo) {
        TbHouseGroupBuying tbHouseGroupBuying = new TbHouseGroupBuying();
        BeanUtils.copyProperties(tbHouseGroupBuyingVo,tbHouseGroupBuying);
        int flag = tbHouseGroupBuyingMapper.updateById(tbHouseGroupBuying);
        return flag>0?ResultVo.SUCCESS():ResultVo.FAILED(ResponseState.UPDATE_ERROR);
    }

    @Override
    public ResultVo getList(TbHouseGroupBuyingSearchVo tbHouseGroupBuyingSearchVo) {
        Page<TbHouseGroupBuying> page = new Page<>(tbHouseGroupBuyingSearchVo.getPageNum(), tbHouseGroupBuyingSearchVo.getPageSize());
        Page<TbHouseGroupBuyingVo> pageList = tbHouseGroupBuyingMapper.getList(page,tbHouseGroupBuyingSearchVo);
        return ResultVo.SUCCESS(pageList);
    }
}




